package cn.blackhole.simple.domain.Metric.service;

import cn.blackhole.simple.common.enums.InterfaceType;
import cn.blackhole.simple.domain.Metric.model.entity.ExceptionStat;
import cn.blackhole.simple.domain.Metric.model.entity.MetricData;
import cn.blackhole.simple.domain.Metric.model.objValue.MetricType;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public interface MetricsCollector {

    // 记录基础指标
    void recordMetric(MetricData data);

    // 记录响应时间（百分位数统计）
    default void recordResponseTime(InterfaceType type, long durationMs) {
        recordMetric(new MetricData("http", type, MetricType.RESPONSE_TIME, durationMs));
    }

    // 记录异常信息
    default void recordException(InterfaceType type, Throwable ex) {
        Map<String, String> tags = new HashMap<>();
        tags.put("exception", ex.getClass().getSimpleName());
        recordMetric(new MetricData("http", type, MetricType.FAILED_REQUESTS, 1, tags));
    }

    // 获取统计数据
    Map<InterfaceType, Map<MetricType, Double>> getMetrics();

    List<ExceptionStat> getExceptionStats();
}